<html>
<head><meta charset="utf-8"><title>bikesheddable: get/set + _dyn? · project-portable-simd · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/index.html">project-portable-simd</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html">bikesheddable: get/set + _dyn?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="227119716"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/227119716" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#227119716">(Feb 20 2021 at 21:43)</a>:</h4>
<p>So,<code>simd_extract</code> and <code>simd_insert</code> allow you to mess with individual values in a vector. If the index is known constantly, this is faster / better codegen, given that many architectures <em>cough x86 cough</em> have instructions that prefer immediates here. Per our approach to shuffles, we have established a generic desire to want to allow developers to be confident they are setting const values when this matters, and thus to expose const vs. dynamic APIs.</p>
<p>I kind of want to use <code>fn get</code> and <code>fn set</code> as the methods to do this for our vector types, because <del>that's the term Arm NEON uses</del> "extract" is a bit ambiguous with some possible shuffles we might want to offer and overall I think it's a bit cleaner than "insert", but this admittedly results in</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="cp">#[test]</span><span class="w"></span>
<span class="cp">#[cfg_attr(target_arch = </span><span class="s">"wasm32"</span><span class="cp">, wasm_bindgen_test)]</span><span class="w"></span>
<span class="k">fn</span> <span class="nf">simple_insert</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">SimdF32</span>::<span class="n">from_array</span><span class="p">([</span><span class="o">-</span><span class="mf">3.0</span><span class="p">,</span><span class="w"> </span><span class="mf">5.0</span><span class="p">,</span><span class="w"> </span><span class="mf">2.0</span><span class="p">,</span><span class="w"> </span><span class="o">-</span><span class="mf">0.0</span><span class="p">]);</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">a</span><span class="p">.</span><span class="n">set</span>::<span class="o">&lt;</span><span class="mi">2</span><span class="o">&gt;</span><span class="p">(</span><span class="mf">9.1e3</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="fm">assert_eq!</span><span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">to_array</span><span class="p">(),</span><span class="w"> </span><span class="p">[</span><span class="o">-</span><span class="mf">3.0</span><span class="p">,</span><span class="w"> </span><span class="mf">5.0</span><span class="p">,</span><span class="w"> </span><span class="mf">9.1e3</span><span class="p">,</span><span class="w"> </span><span class="o">-</span><span class="mf">0.0</span><span class="p">]);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>which is kind of an unexpected pattern.</p>



<a name="227119817"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/227119817" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#227119817">(Feb 20 2021 at 21:44)</a>:</h4>
<p>otoh I don't think it's <strong>bad</strong> either, so!</p>



<a name="227119861"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/227119861" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#227119861">(Feb 20 2021 at 21:45)</a>:</h4>
<p>So, unlike shuffles, is there any reason to think codegen wouldn't use the immediate variant if possible?  Since it's only a single integer argument it should do a good job reasoning about it</p>



<a name="227120055"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/227120055" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#227120055">(Feb 20 2021 at 21:48)</a>:</h4>
<p>atm for more dynamic indicing we already have Index/IndexMut, I should note!</p>



<a name="227120066"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/227120066" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#227120066">(Feb 20 2021 at 21:49)</a>:</h4>
<p>( it's a good question tho'. )</p>



<a name="227120083"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/227120083" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#227120083">(Feb 20 2021 at 21:49)</a>:</h4>
<p>What I mean is, is there any reason to suspect Index/IndexMut won't generate the more optimal forms if the index is a constant</p>



<a name="227120142"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/227120142" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#227120142">(Feb 20 2021 at 21:50)</a>:</h4>
<p>Via const propagation etc I'd expect LLVM to know</p>



<a name="227124075"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/227124075" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#227124075">(Feb 20 2021 at 22:40)</a>:</h4>
<p>uh, based on what i know of stdarch, llvm would not "just know"</p>



<a name="227124092"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/227124092" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#227124092">(Feb 20 2021 at 22:41)</a>:</h4>
<p>like, there's a whole thing with these dumb macros to "constify" the inputs of the args of these intrinsics that take const args</p>



<a name="227124122"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/227124122" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#227124122">(Feb 20 2021 at 22:41)</a>:</h4>
<p>which they're <em>already</em> trying to undo and take out now that min-const-generics is going to be a thing, because the macros are wildly bad for compilation time</p>



<a name="227124234"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/227124234" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#227124234">(Feb 20 2021 at 22:43)</a>:</h4>
<p>That's because LLVM requires those arguments to be immediate</p>



<a name="227124247"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/227124247" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#227124247">(Feb 20 2021 at 22:43)</a>:</h4>
<p>This is just an optimization</p>



<a name="227124269"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/227124269" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#227124269">(Feb 20 2021 at 22:43)</a>:</h4>
<p>I would honestly expect it to do the same optimization when working with small arrays</p>



<a name="227124416"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/227124416" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#227124416">(Feb 20 2021 at 22:45)</a>:</h4>
<p>i suppose if we don't have to assure anyone that a specific instruction is being used it's all fine</p>



<a name="227124484"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/227124484" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#227124484">(Feb 20 2021 at 22:46)</a>:</h4>
<p>personally i think that get and set with min const generics is just weird enough to help convey to people that they really shouldn't be doing that too much</p>



<a name="227124623"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/227124623" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#227124623">(Feb 20 2021 at 22:48)</a>:</h4>
<blockquote>
<p>The first operand of an ‘insertelement’ instruction is a value of vector type. The second operand is a scalar value whose type must equal the element type of the first operand. The third operand is an index indicating the position at which to insert the value. The index may be a variable of any integer type.</p>
</blockquote>



<a name="227124630"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/227124630" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#227124630">(Feb 20 2021 at 22:48)</a>:</h4>
<p>"it's weird, and that's good actually" is an amusing take.</p>



<a name="227124654"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/227124654" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#227124654">(Feb 20 2021 at 22:48)</a>:</h4>
<p>I don't believe LLVM even has an instruction for const index insert/extract</p>



<a name="227124687"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/227124687" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#227124687">(Feb 20 2021 at 22:49)</a>:</h4>
<p>If we do it with const generics it's still just relying on the optimizer to notice the index is const</p>



<a name="227124993"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/227124993" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#227124993">(Feb 20 2021 at 22:53)</a>:</h4>
<p><span class="user-mention" data-user-id="281757">@Jubilee</span> it's always the most important take. Weird things should be weird for notable reasons, and if it's not weird then the interface shouldn't be weird either.</p>



<a name="227125057"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/227125057" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#227125057">(Feb 20 2021 at 22:54)</a>:</h4>
<p>it's like a comic book or a high school movie: anything that stands out needs a clear schtick</p>



<a name="227125073"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/227125073" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#227125073">(Feb 20 2021 at 22:54)</a>:</h4>
<p><span class="user-mention" data-user-id="312331">@Caleb Zulawski</span> oh if the const thing is a fake requirement then we don't need to keep it around.</p>



<a name="227125078"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/227125078" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#227125078">(Feb 20 2021 at 22:54)</a>:</h4>
<p>I think get/set on masks is a good example.  You can't just access the elements there because they're not bools</p>



<a name="227125115"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/227125115" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#227125115">(Feb 20 2021 at 22:55)</a>:</h4>
<p>Well on the Intel intrinsics I'm positive they're real, but in generic LLVM there is no such requirement as far as I can tell</p>



<a name="227125183"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/227125183" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#227125183">(Feb 20 2021 at 22:56)</a>:</h4>
<p>i think masks is actually not the best example because, since we're handling it within a method call, you <em>can</em> just take a bool and return a bool and fiddle the data on the library's end so the user never needs to care about the difference</p>



<a name="227125192"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/227125192" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#227125192">(Feb 20 2021 at 22:56)</a>:</h4>
<p>since we're not indexing and getting a <code>&amp;mut bool</code> for the user to write to, then it doesn't matter that they're fake bools</p>



<a name="227125198"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/227125198" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#227125198">(Feb 20 2021 at 22:56)</a>:</h4>
<p>Sorry, I meant it has a good reason to be "weird" and by weird I mean not using Index</p>



<a name="227125201"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/227125201" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#227125201">(Feb 20 2021 at 22:56)</a>:</h4>
<p>ah, right</p>



<a name="227125233"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/227125233" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#227125233">(Feb 20 2021 at 22:57)</a>:</h4>
<p>well i think the same logic roughly holds: we don't (generally) want people making references into the middle of a simd value</p>



<a name="227125250"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/227125250" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#227125250">(Feb 20 2021 at 22:58)</a>:</h4>
<p>Well, with neon it's free</p>



<a name="227125297"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/227125297" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#227125297">(Feb 20 2021 at 22:58)</a>:</h4>
<p>But I don't think there's any reason to promote it any more than just using Index</p>



<a name="227125299"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/227125299" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#227125299">(Feb 20 2021 at 22:58)</a>:</h4>
<p>yeah but remember this is a lowest common denominator api, in general</p>



<a name="227125326"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/227125326" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#227125326">(Feb 20 2021 at 22:59)</a>:</h4>
<p>Yeah.  There are still definitely reasons to do it</p>



<a name="227125337"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/227125337" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#227125337">(Feb 20 2021 at 22:59)</a>:</h4>
<p>expected grouchy SIMD programmer take: but I wanna <strong>know</strong> that it's const!</p>



<a name="227125342"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/227125342" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#227125342">(Feb 20 2021 at 22:59)</a>:</h4>
<p>Some fast fourier transform kernels do it since you need to conjugate the third element of the vector</p>



<a name="227125380"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/227125380" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#227125380">(Feb 20 2021 at 23:00)</a>:</h4>
<p>Even on x86-64</p>



<a name="227125634"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/227125634" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#227125634">(Feb 20 2021 at 23:04)</a>:</h4>
<p><span class="user-mention" data-user-id="281757">@Jubilee</span> I imagine LLVM's lowering code just says "if index is const do this, if not do that"</p>



<a name="227125651"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/227125651" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#227125651">(Feb 20 2021 at 23:04)</a>:</h4>
<p>My understanding is that the point of const propagation was to enable more LLVM optimizations like that, not to help anything in rustc itself</p>



<a name="227125954"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/227125954" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#227125954">(Feb 20 2021 at 23:10)</a>:</h4>
<p>I will say though that it's like relying on rustc or LLVM to not interpret that as "place value on stack, now write into array". <span aria-label="grimacing" class="emoji emoji-1f62c" role="img" title="grimacing">:grimacing:</span></p>



<a name="227126593"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/227126593" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#227126593">(Feb 20 2021 at 23:23)</a>:</h4>
<p>you <em>can</em> know it's const: assign it to a const and pass that const to the indexing function</p>



<a name="227126597"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/227126597" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#227126597">(Feb 20 2021 at 23:23)</a>:</h4>
<p>:3333</p>



<a name="227127383"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/227127383" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#227127383">(Feb 20 2021 at 23:36)</a>:</h4>
<p>whew</p>



<a name="233861090"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/233861090" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#233861090">(Apr 09 2021 at 17:28)</a>:</h4>
<p>I want to have some kind of codegen tests for this so we can see if there's a difference.</p>



<a name="233883128"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/233883128" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#233883128">(Apr 09 2021 at 20:06)</a>:</h4>
<p>since Index/IndexMut requires taking the address of the vector, there are a lot of ways this kind of thing can confuse LLVM ime</p>



<a name="233883415"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/233883415" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#233883415">(Apr 09 2021 at 20:08)</a>:</h4>
<p>IMO Index/IndexMut might a reasonable thing to use as the dynamic version of the api, but would be nice to have a const version. that said i think simd code doesn't do this that much IME</p>



<a name="233883488"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/233883488" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#233883488">(Apr 09 2021 at 20:09)</a>:</h4>
<p>Fwiw the arm vendor API explicitly supports indexing that way in the C api</p>



<a name="233883639"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/233883639" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#233883639">(Apr 09 2021 at 20:10)</a>:</h4>
<p>I would imagine any issues there would have been shaken out in clang</p>



<a name="233883771"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/233883771" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#233883771">(Apr 09 2021 at 20:11)</a>:</h4>
<p>Also my point wrt consts is if you look at LLVM IR, there is no const version, that's specifically part of the Intel vendor API</p>



<a name="233884402"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/233884402" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#233884402">(Apr 09 2021 at 20:17)</a>:</h4>
<p>llvm has never been above special casing consts in the c++</p>



<a name="233886040"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/233886040" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#233886040">(Apr 09 2021 at 20:31)</a>:</h4>
<p><span class="user-mention silent" data-user-id="312331">Caleb Zulawski</span> <a href="#narrow/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F/near/233883488">said</a>:</p>
<blockquote>
<p>Fwiw the arm vendor API explicitly supports indexing that way in the C api</p>
</blockquote>
<p>indexing this way as in an analogue to IndexMut? like, pointer-based?</p>



<a name="233887335"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/233887335" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#233887335">(Apr 09 2021 at 20:42)</a>:</h4>
<p>Yeah, like this:</p>
<div class="codehilite"><pre><span></span><code>#include &lt;arm_neon.h&gt;

void foo(float *p, int i) {
    auto v = vld1q_f32(p);
    v[i] = 0;
    vst1q_f32(p, v);
}
</code></pre></div>



<a name="233888051"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/233888051" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#233888051">(Apr 09 2021 at 20:49)</a>:</h4>
<p>That seems notably different to me. My point is that the IndexMut trait is &amp;mut Vector =&gt; &amp;mut Elem</p>



<a name="233888206"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/233888206" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#233888206">(Apr 09 2021 at 20:50)</a>:</h4>
<p>I don't see how we could implement that using vld1q and vst1q, for example</p>



<a name="233888303"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/233888303" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#233888303">(Apr 09 2021 at 20:51)</a>:</h4>
<p>Oh, you mean the vector is taken by reference.  There's no way to avoid that, the repr(simd) calling convention is that all vectors are always taken by reference</p>



<a name="233888305"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/233888305" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#233888305">(Apr 09 2021 at 20:51)</a>:</h4>
<p>(its totally possible to implement with pointer arithmetic and casting and the like, of course</p>



<a name="233888389"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/233888389" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#233888389">(Apr 09 2021 at 20:52)</a>:</h4>
<p>The dereferences are optimized out of course</p>



<a name="233888399"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/233888399" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#233888399">(Apr 09 2021 at 20:52)</a>:</h4>
<p>calling convention isn't super relevant here, since we expect these ops to be inlined</p>



<a name="233888469"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/233888469" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#233888469">(Apr 09 2021 at 20:53)</a>:</h4>
<p>I think it is, if you look at the generated unoptimized LLVM IR, all accesses to vectors go through references</p>



<a name="233888617"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/233888617" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#233888617">(Apr 09 2021 at 20:55)</a>:</h4>
<p>here's llvm ir generated by clang: <a href="https://gcc.godbolt.org/z/hr6jKPT9e">https://gcc.godbolt.org/z/hr6jKPT9e</a></p>



<a name="233892722"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/233892722" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#233892722">(Apr 09 2021 at 21:14)</a>:</h4>
<p>Here's a rust example using <code>IndexMut</code>: <a href="https://rust.godbolt.org/z/vehdKze8v">https://rust.godbolt.org/z/vehdKze8v</a></p>



<a name="233893006"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/233893006" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#233893006">(Apr 09 2021 at 21:16)</a>:</h4>
<p>Remember <code>IndexMut</code> can panic, so that function itself is a little verbose, but calling it with a const index optimizes to <code>insertelement</code></p>



<a name="233893252"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/233893252" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#233893252">(Apr 09 2021 at 21:17)</a>:</h4>
<p>also yes I just realized my naming has an off-by-one error :)</p>



<a name="233907725"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/233907725" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#233907725">(Apr 09 2021 at 23:49)</a>:</h4>
<p><span class="user-mention silent" data-user-id="312331">Caleb Zulawski</span> <a href="#narrow/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F/near/233883488">said</a>:</p>
<blockquote>
<p>Fwiw the arm vendor API explicitly supports indexing that way in the C api</p>
</blockquote>
<p>Arm also provides intrinsics for these tho'</p>



<a name="233908218"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/233908218" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#233908218">(Apr 09 2021 at 23:55)</a>:</h4>
<p>Oh my point was more that this api already exists for some vendors</p>



<a name="233910084"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/233910084" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#233910084">(Apr 10 2021 at 00:18)</a>:</h4>
<p>ah</p>



<a name="233922754"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/233922754" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#233922754">(Apr 10 2021 at 03:49)</a>:</h4>
<p>i'm not sure that i follow how vld1q/vst1q as shown are equivalent to this?</p>



<a name="233923451"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/233923451" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#233923451">(Apr 10 2021 at 04:02)</a>:</h4>
<p>the accessing with <code>[]</code> instead of an intrinsic was the point</p>



<a name="233923495"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/233923495" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#233923495">(Apr 10 2021 at 04:03)</a>:</h4>
<p>I just needed a vector</p>



<a name="233953087"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/233953087" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#233953087">(Apr 10 2021 at 12:54)</a>:</h4>
<p>oh, that's present in clang and gcc on all vector apis though, that's part of the "extended vector types" extension</p>



<a name="233953728"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/233953728" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#233953728">(Apr 10 2021 at 13:05)</a>:</h4>
<p>Oh I wasn't aware, I never use extensions, I just knew it was part of the arm API</p>



<a name="233953812"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/233953812" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#233953812">(Apr 10 2021 at 13:06)</a>:</h4>
<p>Yah, and at least gcc back in the day used to be a bit unpredictable with how the some of the magic would be compiled, to the point where we banned all of it at a place i worked</p>



<a name="233953820"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/233953820" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#233953820">(Apr 10 2021 at 13:06)</a>:</h4>
<p>Is my example convincing to everyone that LLVM is just fine at optimizing through references and generating <code>insertvector</code> when reasonable?</p>



<a name="233954160"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/233954160" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#233954160">(Apr 10 2021 at 13:11)</a>:</h4>
<p>i think the question is probably if it will do that in some patterns you see in batch processing, where there's a lot more pointers involved which could confuse llvm. also, i suspect for some cases a non-mutating "return new vector with this value in that slot" api is decidedly cleaner.</p>



<a name="233954173"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/233954173" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#233954173">(Apr 10 2021 at 13:11)</a>:</h4>
<p>that said at the end of the day i dont think this is an api that matters not much, since its fundamentally 1 item at a time</p>



<a name="233954180"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/233954180" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#233954180">(Apr 10 2021 at 13:11)</a>:</h4>
<p>so im not willing to fight that hard here</p>



<a name="233954278"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/233954278" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#233954278">(Apr 10 2021 at 13:12)</a>:</h4>
<p>That's a good point about the non-mutating API</p>



<a name="233954290"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/233954290" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#233954290">(Apr 10 2021 at 13:13)</a>:</h4>
<p>Not sure how important it is but it's the most notable difference</p>



<a name="233954393"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/bikesheddable%3A%20get/set%20%2B%20_dyn%3F/near/233954393" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/bikesheddable.3A.20get.2Fset.20.2B.20_dyn.3F.html#233954393">(Apr 10 2021 at 13:14)</a>:</h4>
<blockquote>
<p>i think the question is probably if it will do that in some patterns you see in batch processing, where there's a lot more pointers involved which could confuse llvm. </p>
</blockquote>
<p>and whether or not whatever the answer there is stays true after <del>we inevitably turn mutable-noalias off when someone hits a new miscompilation</del> ... things happen.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>